﻿using System;
using System.Collections.Generic;

namespace WindowsPhone.CompactContainer.Aggregator
{
    public class LatchManager<T>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="LatchManager{T}"/> class.
        /// </summary>
        public LatchManager()
        {
            CurrentLocks = new List<T>();
        }

        private IList<T> CurrentLocks { get; set; }

        public void RunWithLock(T lockType, Action action)
        {
            if (!CurrentLocks.Contains(lockType))
            {
                CurrentLocks.Add(lockType);
                action();
                CurrentLocks.Remove(lockType);
            }
        }
    }
}
